package com.lagou.order.controller;

import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.Orders;
import com.lagou.order.feign.GoodsFeign;
import com.lagou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private GoodsFeign goodsFeign;

    @Autowired
    private OrderService orderService;

    @GetMapping("/getGood/{id}")
    public Goods getGood(@PathVariable Integer id){
        return goodsFeign.queryById(id);
    }

    @GetMapping("/deleteGood/{id}")
    public int deleteGood(@PathVariable Integer id){
        return goodsFeign.deleteById(id);
    }

    @RequestMapping(value="/update",method= RequestMethod.POST)
    @ResponseBody
    public int updateGood(@RequestBody Goods goods){
        return goodsFeign.updateById(goods);
    }

    @GetMapping("/getAllGoods")
    public List<Goods> getAllGoods(){
        return goodsFeign.queryAll();
    }

    @GetMapping("/query/{id}")
    public Orders query(@PathVariable Integer id){
        return orderService.queryById(id);
    }

    @GetMapping("queryAll")
    public List<Orders> queryAll(){
        return orderService.queryAll();
    }
}
